# -*- coding:utf-8 -*-

# ======= import =======

import idautils
import idaapi
import idc
import ida_funcs
import re


def parse_file(filename):
    with open(filename, mode='r', encoding='utf-8') as file:
        for line in file:
            # 去除行尾的换行符并分割字段
            fields = line.strip().split('  ')
            
            try:
                # 解析地址和名称
                addr = int(fields[0], 16)  # 转换十六进制地址为整数
                name = fields[1]
                
                # 检查是否存在第三个字段（注释）
                # comment = fields[2] if len(fields) > 2 else ""
                
                # 设置函数名和注释
                #idaapi.set_name(addr, name, idaapi.SN_CHECK)
                #idaapi.set_cmt(addr, comment, 0)
                
                print ("addr", addr, "name:", name);
                
                idaapi.set_name(addr, name)
                if len(fields) > 2 :
                    comment = fields[2]
                    ida_funcs.set_func_cmt(addr, comment, 1)
                    print ("comment", comment);
                    
                print ("\n");
                
            except ValueError:
                print("Error parsing line:", line)
                # 在这里添加任何需要的错误处理逻辑，比如跳过当前行或记录错误信息
                continue

# 调用函数并传入文件名
# parse_file("D:/IDA8.3_x32_6007/exportFun2.txt")
#parse_file("D:/IDA8.3_x32_6007/outdata.txt")
parse_file("D:/ida_x64dbg_script/x64dbgPy_Scripts/ALLhookExport.txt")
print ("import over")